using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DSEngine.Core;
using Microsoft.Xna.Framework;
using DSEngine.Stage;

namespace DSEngine.Sprite
{
    public class SpRepeatTexture : SpDrawableObject
    {
        public SpRepeatTexture(Layout l,string assitName)
            : base(l)
        {
            this.Texture = SpTexture.Create(l,assitName);
          
        }
        public override void Init()
        {
            base.Init();
        }
        new protected float Height
        {
            get
            {
                return base.Height;
            }
            set
            {
                base.Height = value;
            }
        }
        new protected float Width
        {
            get
            {
                return base.Width;
            }
            set
            {
                base.Width = value;
            }
        }
        float rWidth, rHeight;
        public  float RepeatWidth
        {
            get
            {
                return rWidth;
            }
            set
            {
                float tmp = value;
                wCount = (int)(tmp / this.Texture.Width);
                if (wCount == 0)
                    wCount = 1;
                rWidth = wCount * this.Texture.Width;
            }
        }
        public  float RepeatHidth
        {
            get
            {
                return rHeight;
            }
            set
            {
                float tmp = value;
                hCount = (int)(tmp / this.Texture.Height);
                if (hCount == 0)
                    hCount = 1;
                rHeight = hCount * this.Texture.Height;
            }
        }
        protected override void InnerUpdate(Microsoft.Xna.Framework.GameTime gt)
        {

        }
        private int wCount;
        private int hCount;
        protected override void InnerDraw(Microsoft.Xna.Framework.GameTime gt)
        { 
            Vector2 oriVector = this.Position;
            Vector2 curPos = this.Position;
            for (int i = 0; i < wCount; i++)
            {
                DrawObject();
                for (int j = 0; j < hCount; j++)
                {
                    DrawObject();
                    curPos.Y += Texture.Height;
                    this.Position = curPos;
                }
                curPos.X += Texture.Width;
                curPos.Y = oriVector.Y;
                this.Position = curPos;
            }
            this.Position = oriVector;
        }
    }
}
